package com.cloud.bssp.java8.lambda;

import lombok.Data;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @description： 使用List的sort方法，对苹果进行排序
 * @author：weirx
 * @date：2021/10/20 9:44
 * @version：3.0
 */
public class TestLambda {

    @Data
    static class Apple {
        private Integer weight;

        public Apple(Integer weight) {
            this.weight = weight;
        }
    }

    public static void main(String[] args) {
        List<Apple> apples = Arrays.asList(
                new Apple(10), new Apple(19), new Apple(9), new Apple(22));
        // lambda表达式，替换匿名类
        apples.sort(Comparator.comparing((Apple::getWeight)));
    }
}
